jQuery(document).ready(function($){

	var insert_media_id = '';

	if(getURLParameter('page') == 'nukes_appointments'){

		//WP Color Picker

		//$('.nuke-color-field').wpColorPicker(); /**Code by coder 3.2.0 */

		

		$('#appointment_date, #app_dob').datetimepicker({ /**Code by coder 3.2.0 */

				dateFormat: 'yy-mm-dd',

				showSecond: true,

				timeFormat: 'HH:mm:ss'

		});

	}

	$('a[id^="insert-media-button"]').live('click', function(e){
		e.preventDefault();
		var prev_id = $(this).prev();
		insert_media_id = $(prev_id).attr('id');
	});
	
	window.send_to_editor = function( html ){
		var src = $( $('img', html) ).attr('src');
		$('#'+insert_media_id).val( src );
	};

	$('#role').change(function(){

		if($(this).val() == 'doctors' && ! $('#createuser').length && pagenow == 'user-edit')

		{

			var data = {action: 'doctor_fields',user_id:$('#user_id').val(),'wpnonce':$('#_wpnonce_create-user').val()};

			

			if( ! $('#doctors_profile').length)

			$(this).parents('.form-table:first').after('<div id="doctors_profile">Loading...</div>');

				

			// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php

			$.post(ajaxurl+'?page=fw_theme_options', data, function(response)

			{

				$('#doctors_profile').html(response);

			});

		}else $('#doctors_profile').remove();

	});

		

	if(getURLParameter('role') == 'doctors'){

		$('#role').val('doctors');

		$('#role').parents('.form-field:first').css('display','none');

		$('#add-new-user').text($('#add-new-user').text().replace(/user/i,'Doctor'));

	}else if(pagenow == 'user-edit' && $('#role').val() == 'doctors'){

			$('#role').parents('tr:first').css('display','none');

			$('h2').html($('h2').html().replace(/user/i, 'Doctor'));

		}

	

	$('#role').trigger('change');

	

	function getURLParameter(name) {

		return decodeURI(

			(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]

		);

	}

});